package util

import (
	"log"
	"os"
	"os/exec"
	"path/filepath"
)

var (
	// RootPath _
	RootPath string
)

func init() {
	RootPath = GetProjectRootPath()
}

// GetProjectRootPath _
func GetProjectRootPath() string {
	f := os.Args[0]
	fPath, e := filepath.Abs(f)
	if e != nil {
		log.Fatalf("err get project path: %v\n", e)
	}
	exePath, e := exec.LookPath(fPath)
	if e != nil {
		log.Fatalf("err get exe path: %v\n", e)
	}
	rootPath := filepath.Dir(exePath)
	log.Println(rootPath)
	return rootPath
}
